<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#no").focus();
			$("#inputForm").validate({
				rules: {
					loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')},
                    mobile: {remote: "${ctx}/sys/user/checkMobile?userId=${user.id}"}
				},
				messages: {
					loginName: {remote: "用户登录名已存在"},
                    mobile: {remote: "手机号码已经存在"}
				},
				submitHandler: function(form){
					loading('<spring:message code="common.subbmiting"/>');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function userTypeChange(){
			var type = $("#role").val();
			console.log(type);
			if(type == "2"){
				$("#depart").hide();
				$("#companyButton").addClass("disabled");
				$("#officeButton").addClass("disabled");
			}else if(type == "3"){
				$("#depart").show();
				$("#companyButton").removeClass("disabled");
				$("#officeButton").addClass("disabled");
			}else if(type == "4"){
				$("#depart").show();
				$("#officeButton").removeClass("disabled");
				$("#companyButton").removeClass("disabled");

			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/user/list">用户列表</a></li>
		<li class="active"><a href="${ctx}/sys/user/form?id=${user.id}">用户<shiro:hasPermission name="sys:user:edit"><spring:message code="common.add"/></shiro:hasPermission><shiro:lacksPermission name="sys:user:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/user/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.account"/>:</label>
			<div class="controls">
				<input id="oldLoginName" name="oldLoginName" type="hidden" value="">
				<form:input path="loginName" htmlEscape="false" maxlength="50" class="required userName"/>
				<span class="help-inline"><font color="red">* 一旦创建就不能修改</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">权限类型:</label>
			<div class="controls">
				<form:select path="role" class="input-xlarge" onchange="userTypeChange();">
					<form:options items="${allRoles}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.name"/>:</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="50" class="required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.phone_number"/>:</label>
			<div class="controls">
				<form:input path="mobile" htmlEscape="false" maxlength="100" class="required mobile"/>
                <span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
        <div class="control-group">
            <label class="control-label">有效期至:</label>
            <div class="controls">
                <input id="avaliDate" name="avaliDate" type="text" readonly="readonly" maxlength="20" class="input-small Wdate required"
                       value="<fmt:formatDate value="${user.avaliDate}" pattern="yyyy-MM-dd"/>"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true,minDate:'%y-%M-{%d+1}'});"/>
                <span class="help-inline"><font color="red">*</font> </span>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label"><spring:message code='common.remarks'/>:</label>
            <div class="controls">
                <form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
            </div>
        </div>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.group.branchoffice"/>:</label>
				<div class="controls">
						<shiro:hasRole name="admin">
						<sys:treeselect id="company" name="company.id" value="" labelName="company.name" labelValue=""
							title="公司" url="/sys/office/treeData?type=1" cssClass="required"  notAllowSelectParent="true" notAllowSelectRoot="true" allowInput="true"  disabled="disabled"/>
					</shiro:hasRole>
                    <shiro:lacksRole name="admin">
                        <input id="companyId" name="company.id" value="${user.company.id}" type="hidden">
                        <input id="companyName" name="company.name" value="${user.company.name}" type="hidden">
                        <label class="lbl">${user.company.name}</label>
                    </shiro:lacksRole>
                    <span class="help-inline"><font color="red">* 一旦创建就不能修改</font> </span>
				</div>
		</div>
		<div class="control-group" id="depart" <shiro:hasRole name="admin">style="display:none;" </shiro:hasRole> >
			<label class="control-label"><spring:message code="common.group"/>:</label>
			<div class="controls">
				<shiro:hasAnyRoles  name="admin">
                	 <sys:treeselect id="office" name="office.id" value="" labelName="office.name" labelValue=""
					title="部门" url="/sys/office/treeData?type=2" cssClass="required" notAllowSelectParent="true" notAllowSelectRoot="true" allowInput="true" disabled="disabled"/>		
				</shiro:hasAnyRoles>
				<shiro:hasAnyRoles  name="areaadmin">
                	 <sys:treeselect id="office" name="office.id" value="" labelName="office.name" labelValue=""
					title="部门" url="/sys/office/treeData?type=2" cssClass="required" notAllowSelectParent="true" notAllowSelectRoot="true" allowInput="true" disabled="disabled"/>		
				</shiro:hasAnyRoles>
				<shiro:hasAnyRoles  name="operate,user">
                	<input id="officeId" name="office.id" value="${user.office.id}" type="hidden">
                    <input id="officeName" name="office.name" value="${user.office.name}" type="hidden">
                    <label class="lbl">${user.office.name}</label>		
				</shiro:hasAnyRoles>
				<span class="help-inline"><font color="red">* 一旦创建就不能修改</font> </span>
		</div>
		</div>
	
		<div class="form-actions">
			<shiro:hasPermission name="sys:user:check">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="下一步"/>&nbsp;
			</shiro:hasPermission>
			<shiro:lacksPermission name="sys:user:check">
				<shiro:hasPermission name="sys:user:edit">
					<input id="btnSubmit" class="btn btn-primary" type="submit" value="下一步"/>&nbsp;
				</shiro:hasPermission>
			</shiro:lacksPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>